package com.zkca.xf.ui.activity.me;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.zkca.xf.Constants_SP;
import com.zkca.xf.R;
import com.zkca.xf.base.BaseTitleActivity;
import com.zkca.xf.model.javabean.PasswordBean;
import com.zkca.xf.presenter.ChangeQasswordPresenter;
import com.zkca.xf.utils.DES3;
import com.zkca.xf.utils.SPUtil;
import com.zkca.xf.utils.ToastUtils;
import com.zkca.xf.view.ChangeQasswordView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChangeQasswordActivity extends BaseTitleActivity implements ChangeQasswordView {

    @BindView(R.id.et_affirm_paw)
    EditText et_affirm_paw;
    @BindView(R.id.et_paw)
    EditText et_paw;
    private ChangeQasswordPresenter changeQasswordPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_qassword);
        ButterKnife.bind(this);
        setTitleText("修改密码");
        setleftTextVisibility(true);
        setleftImgVisibility(true);
        changeQasswordPresenter=new ChangeQasswordPresenter(this,this);
    }



    @OnClick({R.id.tv_submit})
    public void onClick(View view){
        switch (view.getId()) {
            case R.id.tv_submit:
                String affirm_password = et_affirm_paw.getText().toString().trim();
                String password = et_paw.getText().toString().trim();
                if(!password.equals(affirm_password)){
                    ToastUtils.show(ChangeQasswordActivity.this,"两次的密码不一致");
                    return;
                }


                String user_id =  SPUtil.getString(this,Constants_SP.USER_ID, "");
                Map<String, String> map = new HashMap<>();
                String userPsw = null;
                try {
                    userPsw = new DES3().encode(password);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                map.put("userId", user_id);
                map.put("newPwd",userPsw);
                changeQasswordPresenter.ChangeQassword(map);
                break;
        }
    }

    @Override
    public void showProgressDialog() {

    }

    @Override
    public void hideProgressDialog() {

    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void getChangeQassword(PasswordBean passwordBean) {
        ToastUtils.show(ChangeQasswordActivity.this,"密码修改成功");
        ChangeQasswordActivity.this.finish();
    }
}
